package xyz.fivefaith.tool.mybatis.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;

import org.apache.ibatis.session.Configuration;

import xyz.fivefaith.tool.mybatis.injector.method.AlwaysSelectBatchIds;
import xyz.fivefaith.tool.mybatis.injector.method.AlwaysSelectById;
import xyz.fivefaith.tool.mybatis.injector.method.AlwaysSelectCount;
import xyz.fivefaith.tool.mybatis.injector.method.AlwaysSelectList;
import xyz.fivefaith.tool.mybatis.injector.method.AlwaysUpdate;

import java.util.List;

/**
 * @author zhaoanchi
 * @version 1.0
 * @since 2023-09-18 15:17
 */
public class FaithInjector extends DefaultSqlInjector {
    public FaithInjector() {
        super();
    }

    /**
     * 获取所有方法列表 目前只mysql测试通过: new InsertBatchSomeColumn(i-> i.getFieldFill() != FieldFill.UPDATE)
     * 常用的 Predicate: 例1: t -> !t.isLogicDelete() , 表示不要逻辑删除字段 例2: t ->
     * !t.getProperty().equals("version") , 表示不要字段名为 version 的字段 例3: t -> t.getFieldFill() !=
     * FieldFill.UPDATE) , 表示不要填充策略为 UPDATE 的字段
     *
     * @param mapperClass 当前mapper
     * @param tableInfo
     * @return
     */
    @Override
    public List<AbstractMethod> getMethodList(
            Configuration configuration, Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> methods = super.getMethodList(configuration, mapperClass, tableInfo);
        methods.add(new AlwaysUpdateSomeColumnById(i -> true));
        methods.add(new AlwaysUpdate(i -> true));
        methods.add(new AlwaysSelectById());
        methods.add(new AlwaysSelectBatchIds());
        methods.add(new AlwaysSelectCount());
        methods.add(new AlwaysSelectList());
        return methods;
    }
}
